package com.viewpagerindicator.sample.adapters;

import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.viewpagerindicator.sample.DeviceActivity;
import com.viewpagerindicator.sample.R;

import java.util.List;


/**
 * Created by zhao on 2015/11/7.
 */
public class DeviceScanListAdapter extends ArrayAdapter<BluetoothDevice> {
    private int resource;
    private LayoutInflater inflater;
    public DeviceScanListAdapter(Context context, int resource, List<BluetoothDevice> objects) {
        super(context, resource, objects);
        this.resource=resource;
        this.inflater=LayoutInflater.from(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null){
            convertView = inflater.inflate(resource, null);
        }
        BluetoothDevice bluetoothDevice=getItem(position);

        TextView textView= (TextView) convertView.findViewById(R.id.goods_item_name);
        textView.setText(getItem(position).getName());

        TextView desctextView= (TextView) convertView.findViewById(R.id.type_item_desc);
        desctextView.setText(getItem(position).getAddress());

        Button button= (Button) convertView.findViewById(R.id.device_pair);
        button.setText(R.string.btn_ok);
        button.setTag(bluetoothDevice);
        button.setOnClickListener((DeviceActivity)getContext());
        return convertView;
    }
}
